home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / dxcmds34.sit / Dartmouth XCMD's 3.4.3 / card_10571.txt < prev    next >
Text File  |  1990-04-17  |  10KB  |  314 lines

  1. -- card: 10571 from stack: in.3
  2. -- bmap block id: 0
  3. -- flags: 4000
  4. -- background id: 8327
  5. -- name: SerialHandler
  6. ----- HyperTalk script -----
  7. on Install
  8.   put ChooseTargetStack() into it
  9.   InstallResource XFCN,SerialHandler,it
  10. end Install
  11.  
  12. on opencard
  13.   set the visible of button "put" to false
  14.   set the visible of button "get" to false
  15.   pass opencard
  16. end opencard
  17.  
  18.  
  19.  
  20. -- part 3 (button)
  21. -- low flags: 00
  22. -- high flags: 8003
  23. -- rect: left=51 top=298 right=320 bottom=151
  24. -- title width / last selected line: 0
  25. -- icon id / first selected line: 0 / 0
  26. -- text alignment: 1
  27. -- font id: 0
  28. -- text size: 12
  29. -- style flags: 0
  30. -- line height: 16
  31. -- part name: SerialHandler
  32. ----- HyperTalk script -----
  33. on mouseUp
  34.   get modaldialog(serialhandler,empty,cardCenter)
  35.   if it is not "cancel" then
  36.     set the visible of button "put" to true
  37.     set the visible of button "get" to true
  38.   end if
  39. end mouseUp
  40.  
  41.  
  42.  
  43. -- part 5 (field)
  44. -- low flags: 01
  45. -- high flags: 2007
  46. -- rect: left=18 top=32 right=284 bottom=486
  47. -- title width / last selected line: 0
  48. -- icon id / first selected line: 0 / 0
  49. -- text alignment: 0
  50. -- font id: 3
  51. -- text size: 10
  52. -- style flags: 0
  53. -- line height: 13
  54. -- part name: Documentation
  55.  
  56.  
  57. -- part 9 (button)
  58. -- low flags: 80
  59. -- high flags: A003
  60. -- rect: left=154 top=293 right=311 bottom=189
  61. -- title width / last selected line: 0
  62. -- icon id / first selected line: 0 / 0
  63. -- text alignment: 1
  64. -- font id: 0
  65. -- text size: 12
  66. -- style flags: 0
  67. -- line height: 16
  68. -- part name: Put
  69. ----- HyperTalk script -----
  70. on mouseUp
  71.   -- You may have to change the parameter list to suit your configuration
  72.   -- NOTE: This button is a self contained operation of open, put,close.
  73.   --       You DO NOT have to open and close every time you get or put.
  74.   --       Just open once and start once, like when you open and close
  75.   --       your stack.
  76.   set the cursor to watch
  77.   get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
  78.   if it is not empty then
  79.     put "Error: "&&it&&" (See script of "put" button)"
  80.   end if
  81.   put the number of lines in the script of me into nl
  82.   repeat with i = 1 to nl
  83.     get line i of the script of me
  84.     get Serialhandler("put","A",it&return&numToChar(10))
  85.   end repeat
  86.   if it is not empty then
  87.     put "Error: "&&it
  88.   end if
  89.   get Serialhandler("close","A")
  90. end mouseUp
  91.  
  92.  
  93.  
  94. -- part 10 (button)
  95. -- low flags: 80
  96. -- high flags: 8003
  97. -- rect: left=187 top=306 right=324 bottom=223
  98. -- title width / last selected line: 0
  99. -- icon id / first selected line: 0 / 0
  100. -- text alignment: 1
  101. -- font id: 0
  102. -- text size: 12
  103. -- style flags: 0
  104. -- line height: 16
  105. -- part name: Get
  106. ----- HyperTalk script -----
  107. on mouseUp
  108.   -- You may have to change the parameter list to suit your configuration
  109.   -- NOTE: This button is a self contained operation of open, get,close.
  110.   --       You DO NOT have to open and close every time you get or put.
  111.   --       Just open once and start once, like when you open and close
  112.   --       your stack.
  113.   set the hilite of me to true
  114.   set the cursor to watch
  115.   get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
  116.   set the visible of card field "got" to true
  117.   put empty into card field "got"
  118.   put "Click the mouse when done."
  119.   put "Characters received on the serial port will appear below:" &return&return into card field "got"
  120.   repeat while the mouse is up
  121.     get SerialHandler("get","A",60)
  122.     put it after card field "got"
  123.   end repeat
  124.   get SerialHandler("close","A")
  125.   set the visible of card field "got" to false
  126.   set the hilite of me to false
  127.   put empty into msg
  128.   hide msg
  129. end mouseUp
  130.  
  131.  
  132.  
  133. -- part 11 (field)
  134. -- low flags: 81
  135. -- high flags: 0007
  136. -- rect: left=18 top=32 right=285 bottom=481
  137. -- title width / last selected line: 0
  138. -- icon id / first selected line: 0 / 0
  139. -- text alignment: 0
  140. -- font id: 3
  141. -- text size: 12
  142. -- style flags: 0
  143. -- line height: 16
  144. -- part name: got
  145.  
  146.  
  147. -- part 12 (field)
  148. -- low flags: 01
  149. -- high flags: 0004
  150. -- rect: left=289 top=288 right=324 bottom=455
  151. -- title width / last selected line: 0
  152. -- icon id / first selected line: 0 / 0
  153. -- text alignment: 0
  154. -- font id: 0
  155. -- text size: 12
  156. -- style flags: 0
  157. -- line height: 16
  158. -- part name: 
  159.  
  160.  
  161. -- part contents for card part 5
  162. ----- text -----
  163. SerialHandler version 1.1a10
  164. Roger Brown, Dartmouth College
  165.  
  166. Serialhandler is a HyperCard XFCN that opens access to the Macintosh serial ports. Several functions are available through the one handler. Each is specified by an opcode in the first parameter. Successive parameters and the return value depend on the opcode.
  167.  
  168. OPCODE          INPUT                              DEFAULT                              OUTPUT
  169. =======         =====                          =======                             =======
  170. "open "             port  (A,B)                     A = modem                           error messages
  171.                          baud (300-9600)        9600                                    if any, or the value of                   
  172.                                                                                                              a handle
  173.                          data bits (5-8)              8                                          to the input buffer if
  174.                          parity (odd,even,none)  none                                     one larger than 64
  175.                          stop bits (1,1.5,2)       1                                           bytes is requested
  176.                          flow control 
  177.                            (XON/XOFF,CTS)          XON/XOFF
  178.                          input buffer size            64  bytes                   
  179.  
  180. "close"              port (A,B)                    A = modem                           none
  181.                          input buffer                  (optional)
  182.  
  183. "put"                 port (A,B)                    A = modem                          error messages
  184.                           source of characters     none
  185.  
  186. "get"                 port (A,B)                     A = modem                           error messages if any,                 
  187.                          timeout (ticks)             30  (1/2 sec)                      or characters received
  188.                        
  189. INVOKING SerialHandler
  190.  
  191.   get SerialHandler(task,port,...)
  192.         
  193.    where   task  is the opcode: open,close,put,or get
  194.                 port is the port to use
  195.                 ... other parameters as in the table above
  196.  
  197. EXAMPLES
  198.  
  199.      1. Opening with no parameters beyond the opcode will give you the defaults.  
  200.           ex. get SerialHandler("open")
  201.   
  202.      2. If you want an input buffer larger than 64 bytes then you must declare a global                   
  203.           variable to be used for only this purpose. Assign the return result of the open call 
  204.           to this global. The value of the global is the memory location of the large buffer. It        
  205.           will be locked until you close the serial port.  It is very important that you do not            
  206.           change the value of this global and that you pass it back to SerialHandler in the "
  207.           close" call before opening SerialHandler again. If you are using both ports, keep a 
  208.           separate buffer global for each.
  209.  
  210.         ex. On OpenPort
  211.                  global serialBufferA       -- declare the global here
  212.                  put SerialHandler("open","A","4800,8,none,1,CTS,1024) into serialBufferA
  213.                   -- open the port and assign a 1024 byte buffer which is remembered in 
  214.                   -- global serialBufferA
  215.              end OpenPort
  216.  
  217.              on ClosePort
  218.                 global serialBufferA
  219.                 get SerialHandler("close","A",serialBufferA) -- close port, dispose  the input 
  220.                 -- buffer 
  221.              end closePort 
  222.  
  223.    3. When getting characters from the port, the timeout parameter is the minimum time 
  224.         that SerialHandler will wait for input. If there are still characters to be read at the 
  225.         end of the timeout period, SerialHandler will keep on reading until there are no    
  226.         more to be read.
  227.  
  228.         ex. put SerialHandler("get","A",60) into charsRecieved
  229.  
  230.     4. get Serialhandler("put","A",the script of this stack) will send the text of the script
  231.         out serial port A, assuming it has been opened.
  232.  
  233. WARNING! If you attempt to open the printer port (port B) and get a return message of 
  234. "Error opening serial port", open the Chooser and make sure that  AppleTalk is INACTIVE!
  235. Just unplugging the network is not enough.
  236.  
  237. REVISION HISTORY
  238. 1.0a0 7/5/88 alpha release 
  239. 1.0a1 7/11/88 mistake in GetSerialChars  - 1st call to SetGetBuff had AinRefNum 
  240.            instead of   port as input
  241. 1.0a2 12/9/88 Call to ResultIs with an empty string was leaving orphan handles in the
  242.            heap.  Also, changed for compilation under LSC 3.0.
  243. 1.1a0 first non-public domain source version
  244. 1.1a7 9/1/89 Fixed bug in OpenSerial default handling that could cause random bus 
  245.            errors.
  246. 1.1a9 Fixed bug in the deallocation of memory if a buffer greater than 64K is used.
  247.           Memory blocks were orphaned if there were multiple opens and closes in a single       
  248.           HyperCard session.
  249. 1.0a10 Won't bomb when called with no parameters at all.
  250.  
  251.  
  252. -- part contents for card part 12
  253. ----- text -----
  254. The source is not in the public domain, sorry.
  255.  
  256. -- part contents for card part 11
  257. ----- text -----
  258. Characters received on the serial port will appear below:
  259.  
  260. on mouseUp
  261.  
  262.   -- You may have to change the parameter list to suit your configuration
  263.  
  264.   -- NOTE: This button is a self contained operation of open, put,close.
  265.  
  266.   --       You DO NOT have to open and close every time you get or put.
  267.  
  268.   --       Just open once and start once, like when you open and close
  269.  
  270.   --       your stack.
  271.  
  272.   set the cursor to watch
  273.  
  274.   global gConfig
  275.  
  276.   --get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
  277.  
  278.   put "get SerialHandler(open,"&gConfig&")" into command
  279.  
  280.   do command
  281.  
  282.   put the result
  283.  
  284.   
  285.  
  286.   --get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
  287.  
  288.   if it is not empty then
  289.  
  290.     put "Error: "&&it&&" (See script of "put" button)"
  291.  
  292.   end if
  293.  
  294.   put the number of lines in the script of me into nl
  295.  
  296.   repeat with i = 1 to nl
  297.  
  298.     get line i of the script of me
  299.  
  300.     get Serialhandler("put","a",it&return&numToChar(10))
  301.  
  302.   end repeat
  303.  
  304.   if it is not empty then
  305.  
  306.     put "Error: "&&it
  307.  
  308.   end if
  309.  
  310.   get Serialhandler("close","ab")
  311.  
  312. end mouseUp
  313.  
  314.